﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace KhuyenMaiVang
{
    public static class Utility
    {
        /// <summary>
        /// If value > max, max will be returned.
        /// If value &lt; min, min will be returned.
        /// If min ≤ value ≥ max, value will be returned.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="value"></param>
        /// <param name="max"></param>
        /// <param name="min"></param>
        /// <returns></returns>
        public static T Clamp<T>(T value, T min, T max) where T : IComparable
        {
            T ret = value;
            if (value.CompareTo(min) < 0)
                ret = min;
            else if (value.CompareTo(max) > 0)
                ret = max;
            return ret;
        }
    }
}